package kroketwebspring.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import kroketwebspring.dao.OrderDAO;
import kroketwebspring.dao.OrderDAOImpl;
import kroketwebspring.dao.ProductDAOImpl;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class OrderCartController extends AbstractController {
	private OrderDAO orderDAO;

	public void setProductDAO(ProductDAOImpl productDAO) {
	}

	public void setOrderDAO(OrderDAOImpl orderDAO) {
		this.orderDAO = orderDAO;
	}

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HttpSession session = request.getSession(true);

		// Get the parameters
		String name = request.getParameter("nam");
		String address = request.getParameter("adr");
		String town = request.getParameter("tow");
		String phone = request.getParameter("pho");
		
		// Put everything in the db
		orderDAO.insertOrderIntoDB(session, name, address, town, phone);

		return new ModelAndView("thanks", null);
	}

}
